Deferred routes drawing, connect route helper and more | This Week in Rails
https://world.hey.com/this.week.in.rails/deferred-routes-drawing-connect-route-helper-and-more-3a1ed1cc
Defer route drawing to the first request, or when url_helpers called by gmcgibbon · Pull Request #52353 · rails/rails · GitHub
railtiesに関する変更です
第23回で紹介した内容の再チャレンジです
#023: Global strict loading mode, route draw deferring - tanaken on Rails - LISTEN
Global strict loading mode setting, route draw deferring and more | This Week in Rails#666451ec4492e80000bb0a37
ルーティングの描画を最初のリクエスト、または、url_helpersが呼ばれるまで遅延する仕組みが実装されました
この実装は何度もトライされています
2024-05-12: https://github.com/rails/rails/pull/51614 1回目
2024-05-24: https://github.com/rails/rails/issues/51906 いくつかの問題が報告される
2024-06-07: https://github.com/rails/rails/pull/52012 2回目
2024-06-22: https://github.com/rails/rails/pull/52189 新たな問題が発覚しリバート
2024-08-09: https://github.com/rails/rails/pull/52353 今回
enable_extension in schema dump doesn't contain schema name · Issue #52312 · rails/rails · GitHub
ActiveRecordに関する変更です
PostgreSQLで拡張機能を有効化した場合のschema dumpに関する修正をしています
実行するマイグレーションファイル
code:rb
class EnablePostgisExtension < ActiveRecord::Migration7.1
def change
create_schema 'myschema'
enable_extension 'myschema.postgis'
end
end
修正前のschema.rb
code:rb
enable_extension "postgis"
修正後のschema.rb
code:rb
enable_extension "myschema.postgis"
のように、スキーマ名が含まれるようになりました
ところで、PostgreSQLの拡張機能とはなんでしょう?
PostgreSQLでは CREATE EXTENSION というコマンドで外部モジュールや追加機能をインストールすることができます
たとえば CREATE EXTENSION "postgis" は地理空間データをサポートする拡張機能を追加します
このほか、よく使われる拡張機能として次のようなものがあります:
uuid-ossp: UUID(Universally Unique Identifier)を生成するための拡張機能
hstore: キーと値のペアを簡単に管理できるデータ型を提供する拡張機能
pgcrypto: 暗号化とハッシュ化機能を提供する拡張機能
Add escape_html_entities option to JSON encoder by Resonious · Pull Request #51272 · rails/rails · GitHub
ActiveSupportに関する変更です
to_json の呼び出しの際に escape_html_entities オプションを指定することで、config.active_support.escape_html_entities_in_json の設定を上書きできるようになりました
これにより、特定のコントローラーでHTMLエスケープの有無を切り替える事が可能になります
code:rb
class MyController < ApplicationController
def index
render json: { hello: "world" }, escape_html_entities: false
end
end
config.active_support.escape_html_entities_in_json については、
Railsガイドに記載の通り
JSONシリアライズに含まれるHTMLエンティティをエスケープするかどうかを指定します。デフォルト値はtrueです。
https://railsguides.jp/configuring.html#config-active-support-escape-html-entities-in-json
具体的にはJSON出力の中で次のような特殊文字がエスケープされます:
< は \u003C にエスケープされます
> は \u003E にエスケープされます
& は \u0026 にエスケープされます
" は \u0022 にエスケープされます
JSONレスポンス内にHTMLタグが混入してもそれがブラウザで意図しない形で解釈されるのを防ぎ、XSS攻撃のリスクを軽減します